import 'package:flutter/material.dart';
import 'package:flutter_app/components/layout.dart';
import 'package:qr_flutter/qr_flutter.dart';
class FixedBuyPage extends StatefulWidget {
  @override
  _FixedBuyPageState createState() => _FixedBuyPageState();
}

Widget RowItems(String left, String right,{TextStyle rightstyle}) {
  return Container(
    padding: EdgeInsets.symmetric(vertical: 8.0),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          left,
          style: TextStyle(color: Colors.black.withOpacity(0.8)),
        ),
        Text(
          right,
          style: rightstyle ?? TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
        ),
      ],
    ),
  );
}

class _FixedBuyPageState extends State<FixedBuyPage> {
  bool isAgree = false;
  void showCharge() {
    GetBottomSheet(
      context,
      text: '充币BTC',
      children: [
        SizedBox(height: 20),
        Container(
          padding: EdgeInsets.all(19.0),
          decoration: BoxDecoration(
            image: DecorationImage(
              // alignment: Alignment(0.9, 0.5),
              image:
              AssetImage("assets/images/bg_qrcode_frame.png"),
              fit: BoxFit.contain,
            ),
          ),
          child: QrImage(
            //二维码设置前后背景色，不设置的情况下保存图片后因为是png格式的，白色透明的地方都是黑色的，导致查看图片时就是一个黑图
            foregroundColor: Colors.black, //前景色
            backgroundColor: Colors.white, //背景色
            data: "123333",
            size: 160,
          ),
        ),
        SizedBox(height: 20),
        GreyContainer(
          margin: EdgeInsets.only(right: 15.0),
          child: Text(
            '0XSHI908888...XHSAKSH7782BHSAHI9088',
            style: TextStyle(color: Colors.black45),
          ),
        ),
        SizedBox(
            height: 20
        ),
        Container(
          height: 45,
          width: 200,
          child: FlatButton(
              color: Colors.blueAccent,
              textColor: Colors.white,
              onPressed: () {},
              child: Text('复制地址')
          ),
        ),
        SizedBox(
            height: 20
        ),
      ],
    );
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          brightness: Brightness.light,
          iconTheme: IconThemeData(
            color: Colors.black
          ),
          backgroundColor: Colors.transparent,
          elevation: 0,
          title: Text(
            '购买',
            style: TextStyle(
              color: Colors.black,
              fontSize: 18
            ),
          ),
          centerTitle: true,
        ),
        body: Container(
          padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 15.0),
          child: ColumnStart(
            children: [
              Expanded(
                  child: ColumnStart(
                children: [
                  Stack(
                    children: [
                      TextField(
                        autofocus: true,
                        decoration: InputDecoration(
                            hintText: "100 USDT 起投",
                            contentPadding:EdgeInsets.only(right:200)
                        ),
                      ),
                      Positioned(
                          right:0,
                          child: Row(
                            children: [
                              TextButton(child: Text('Max',style: TextStyle(color: Colors.blueAccent,fontSize: 16,fontWeight: FontWeight.w500),),),
                              VerticalDivideLine(),
                              SizedBox(
                                  width:16
                              ),
                              GestureDetector(
                                // onTap: () => showSelectCoin(),
                                child: Row(children: [
                                  Image.asset('assets/images/coins/ic_usdc.png',width: 25,height: 25,),
                                  SizedBox(
                                      width:6.0
                                  ),
                                  Text('USDC',style:TextStyle(fontWeight: FontWeight.w600,fontSize: 16)),
                                ]),
                              )
                            ],
                          ))
                    ],
                  ),
                  Row(
                    children: [
                      Text('账户余额：0 USDT',style: TextStyle(fontSize: 15),),
                      TextButton(onPressed: showCharge, child: Text('充币'))
                    ],
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Text(
                    '投资信息',
                    style: TextStyle(color: Colors.black, fontSize: 16),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Container(
                    padding:
                        EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
                    decoration: BoxDecoration(
                        color: Colors.blueGrey.withOpacity(0.03),
                        borderRadius: BorderRadius.circular(5)),
                    child: Column(
                      children: [
                        RowItems('年华收益率', '15.00%'),
                        RowItems('年限', '14天'),
                        RowItems('到期时间', '2021-03-13 00:00'),
                        RowItems('预期收益', '0.38 USDC',rightstyle:TextStyle(color: Colors.blueAccent,fontWeight: FontWeight.w600)),
                        RowItems('预期回款', '111.38 USDC',rightstyle:TextStyle(color: Colors.blueAccent,fontWeight: FontWeight.w600)),
                      ],
                    ),
                  )
                ],
              )),
              //  bottom
              ColumnStart(
                children: [
                  Row(
                    children: [
                      SizedBox(
                        height: 24.0,
                        width: 24.0,
                        child: Checkbox(
                          value: isAgree,
                          onChanged: (bool value) {
                            setState(() {
                              this.isAgree = value;
                            });
                          },
                        ),
                      ),
                      SizedBox(width: 5),
                      Text('我已阅读且同意'),
                      TextButton(
                        onPressed: () {Navigator.pushNamed(context, '/fixed/agreement');},
                        child: Text(
                          ' 固收产品协议',
                          style: TextStyle(color: Colors.blueAccent),
                        ),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Container(
                      color: Colors.blueAccent,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          FlatButton(
                              onPressed: () {},
                              textColor: Colors.white,
                              child: Text('确认购买')),
                        ],
                      ))
                ],
              )
            ],
          ),
        ));
  }
}
